#!/bin/bash
########################################################################
####  Script Name: sm-lib-2008-fixes
####  version: 1.4.2
####  Date: 2008-12-26

####  Copyright (C) Harald Hope 2005-2008
####  This program is free software; you can redistribute it and/or modify it under
####  the terms of the GNU General Public License as published by the Free Software
####  Foundation; either version 2 of the License, or (at your option) any later version.

####  This program is distributed in the hope that it will be useful, but WITHOUT
####  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
####  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

####  Get the full text of the GPL here:
####  http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

####  Script Author: Harald Hope
####  This is a library file for smxi and cannot be run independently

####  Script URL: http://smxi.org/sm/sm-lib-2008-fixes
####  Script SVN: http://code.google.com/p/smxi
####  Script Home page: http://techpatterns.com/forums/about736.html
########################################################################
#### $DISTRO_VERSION numbers / distro name:
#### 5 sidux test pre release, kanotix/debian conversions ( debian - d:d )
#### 6 chaos, 7 tartaros, 8 gaia, 9 eros - 2007-01/4
#### 10, 11, 12, 13 - 2008-01/4
#### 14, 15, 16, 17 - 2009-01/4
########################################################################

###---------------------------------------------------------------------
### script executor
###---------------------------------------------------------------------
# args: $1 - pre / post
run_2008_fixes()
{
	if [ "$1" == 'pre' ];then
		if [ "$DISTRO_LEVEL" -lt 11 ];then
			sidux_security_patch_1
			libdjvulibre15_fix_1
			update_amarok_xine_1
			busybox_fix_1 # this is also fired in libc6  fix
			libstlport4_fix_1
			amsn_fix_1
			console_tools_kbd_fix_1
			b43_fwcutter_fix_1
			# libavutil_fix_1 # don't use this
		fi
		if [ "$DISTRO_LEVEL" -lt 12 ];then
			syslinux_fix_1
			gpm_fix_1 # preview requires this fix, unfortunately
			libavutil_fix_1
			libpigment_fix_1
		fi
		if [ "$DISTRO_LEVEL" -lt 13 ];then
			ipw2x00_fix_1
		fi
	elif [ "$1" == 'post' ];then
		:
	fi
}

###---------------------------------------------------------------------
### specific du fixes
###---------------------------------------------------------------------

ipw2x00_fix_1()
{
	local prefId='ipw2x00-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'ipw2100-firmware'  )
	local isInstalled2=$( package_tester 'ipw2200-firmware'  )
	local isAvailable=$( check_package_status 'firmware-ipw2x00' )

	if [ "$smPref" -eq 0 -a -n "$isAvailable" ] && [ -n "$isInstalled" -o -n "$isInstalled2" ];then
		echo $LINE
		echo "${S}Running ${C}ipw2x00${S} update fix now. This will replace the older firmware"
		echo "with the new Debian package. You will be asked to agree to the firmware license,"
		echo "you must do this to complete the installation.${N}"
		print_hec
		if [ -n "$isInstalled" ];then
			package_remover 'ipw2100-firmware' 'purge -y'
		fi
		if [ -n "$isInstalled2" ];then
			package_remover 'ipw2200-firmware' 'purge -y'
		fi
		package_installer 'firmware-ipw2x00' 'force-always'
		set_sticky_prefs $prefId
	fi
}

# sidux security advisory, 2008-11-18
sidux_security_patch_1()
{
	local prefId='sidux-security-fix-1'
	local smPref=$( sm_pref_tester $prefId )

	if [ "$smPref" -eq 0 -a -f $ESV ];then
		echo $LINE
		echo "${S}Running ${C}sidux config file removal${S} security fix now...${N}"
		find /root /home -maxdepth 2 -type f -name '.sidconf*' -delete
		set_sticky_prefs $prefId
	fi
}

syslinux_fix_1()
{
	local prefId='syslinux-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'syslinux'  )
	local isAvailable=$( check_package_status 'syslinux-common' )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" -a -n "$isAvailable" ];then
		echo $LINE
		echo "${S}Running ${C}syslinux${S} update fix now...${N}"
		package_remover 'syslinux' 'purge -y'
		package_installer 'syslinux' 'force-always'
		set_sticky_prefs $prefId
	fi
}

libpigment_fix_1()
{
	local prefId='libpigment-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'libpigment0.3-4'  )
	local isAvailable=$( check_package_status 'libpigment0.3-5' )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" -a -n "$isAvailable" ];then
		echo $LINE
		echo "${S}Running ${C}libpigment0.3-4/5${S} update fix now...${N}"
		package_installer 'libpigment0.3-5' 'install-always'
		dpkg --purge libpigment0.3-4
		$APT_TYPE install -f
		set_sticky_prefs $prefId
	fi
}


libdjvulibre15_fix_1()
{
	local prefId='libdjvulibre15-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'libdjvulibre15'  )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" ];then
		echo $LINE
		echo "${S}Running ${C}libdjvulibre15${S} update fix now...${N}"
		package_remover 'libdjvulibre15' 'purge'
		set_sticky_prefs $prefId
	fi
}

gpm_fix_1()
{
	local prefId='gpm-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'gpm'  )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" ];then
		echo $LINE
		echo "${S}Running ${C}gpm${S} update fix now...${N}"
		package_installer 'gpm' 'install-always'
		set_sticky_prefs $prefId
	fi
}

libavutil_fix_1()
{
	local prefId='libavutil-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'libavutilcvs49'  )
	local isInstalled2=$( package_tester 'libavcodeccvs51'  )

	if [ "$smPref" -eq 0 -a "$DISTRO" == 'antix' ] && [ -n "$isInstalled" -o -n "$isInstalled2" ];then
		echo $LINE
		echo "${S}Running ffmpeg fix...${N}"
		#package_installer 'libavutil49 libavcodec51' 'install-always' '-d'
		#echo "${S}Forcing overwrite of broken packages...${N}"
		package_remover 'libavutilcvs49' 'purge'
		$APT_TYPE clean
		package_installer 'ffmpeg' 'install-always'

		#dpkg -i --force-overwrite /var/cache/apt/archives/libavutil49*.deb
		#dpkg -i --force-overwrite /var/cache/apt/archives/libavcodec51*.deb
		set_sticky_prefs $prefId
	fi
}
b43_fwcutter_fix_1()
{
	local prefId='b43-fwcutter-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'b43-fwcutter'  )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" -a "$KERNEL_MATH" -ge 25 ];then
		echo $LINE
		echo "${S}Running ${C}b43-fwcutter${S} fix now...${N}"
		package_remover 'b43-fwcutter' 'purge -y'
		rm -rf /lib/firmware/b43 /lib/firmware/b43legacy
		package_installer 'b43-fwcutter' 'install-always'
		set_sticky_prefs $prefId
	fi
}

console_tools_kbd_fix_1()
{
	local prefId='console-tools-kbd-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'console-tools'  )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" ];then
		echo $LINE
		# odd trick here, this will remove console-tools, only works with apt-get
		package_installer 'kbd' 'install-always' '--purge'
		set_sticky_prefs $prefId
	fi
}

amsn_fix_1()
{
	local prefId='amsn-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'amsn' 'ii' )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" ];then
		echo $LINE
		package_installer 'amsn' 'force-always'
		set_sticky_prefs $prefId
	fi
}

update_amarok_xine_1()
{
	local prefId='amarok-xine-fix-1'
	local smPref=$( sm_pref_tester $prefId )
	local isInstalled=$( package_tester 'amarok-xine' 'ii' )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" ];then
		echo $LINE
		echo "${S}Replacing ${C}amarok-xine${S} with new ${C}amarok-engine-xine${S} now...${N}"
		package_installer 'amarok-engine-xine' 'install-always'
		set_sticky_prefs $prefId
	fi
}

libstlport4_fix_1()
{
	local prefId='libstlport4-fix-3'
	local smPref=$( sm_pref_tester $prefId )

	local isInstalled=$( package_tester 'libstlport4.6c2' )

	if [ "$smPref" -eq 0 -a -n "$isInstalled" ];then
		echo $LINE
		echo "${S}Runnning ${C}libstlport4.6c2${S} fix now. This may also upgrade your ${C}openoffice.org${S}"
		echo "if it's installed due to dependency issues. ${M}You MUST upgrade both now or your dist-upgrade will fail!${N}"
		package_remover 'libstlport4.6c2' 'purge'
		echo "${M}Don't worry if you get an error, just accept ${C}y${M} the next step...${N}"
		dpkg --purge  'libstlport4.6c2'
		$APT_TYPE install -f
		$APT_TYPE install -f
		set_sticky_prefs $prefId
	fi
}

###**EOF**###
